package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author stone
 * @date 2022/08/06 11:39
 */
@RestController
@RequestMapping("user")
public class UserController {

    // 字符串和包装类
    //localhost:8080/user/register1?username=songge&password=niupi&age=40
    @RequestMapping("register1")
    public BaseRespVo register1(String username,String password,Integer age) {
        return BaseRespVo.ok("register1:" + username + "-->" + password + "-->" + age);
    }

    // 字符串和基本类型
    //localhost:8080/user/register2?username=songge&password=niupi
    @RequestMapping("register2")
    public BaseRespVo register2(String username,String password,int age) {
        return BaseRespVo.ok("register2" + username + "-->" + password + "-->" + age);
    }

    //localhost:8080/user/register3?username=songge&password=niupi&age=30
    // &birthday=2022/06/21
    @RequestMapping("register3")
    public BaseRespVo register3(String username, String password, Integer age,
                                Date birthday) {
        return BaseRespVo.ok("register3:" + username + "-->" + password + "-->" + age);
    }


    //localhost:8080/user/register4?username=songge&password=niupi&age=30
    // &birthday=2022-06-21
    @RequestMapping("register4")
    public BaseRespVo register4(String username, String password, Integer age,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        return BaseRespVo.ok("register4:" + username + "-->" + password + "-->" + age);
    }

    //localhost:8080/user/register5?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap
    // &ids=1&ids=2&ids=3
    @RequestMapping("register5")
    public BaseRespVo register5(String username, String password, Integer age,
                                String[] hobbies,
                                Integer[] ids) {
        return BaseRespVo.ok("register5:" + hobbies + "-->" + ids);
    }

    // 前面所有的请求参数都发送了，接收请求参数的方式做了一些变化
    // 采用引用类型的对象来接收请求参数
    //localhost:8080/user/register6?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap
    // &ids=1&ids=2&ids=3
    // &birthday=2022-06-21
    @RequestMapping("register6")
    public BaseRespVo register6(User user) { //应用类型的对象的名称叫啥不重要
        return BaseRespVo.ok("register6:" + user);
    }
    /*@RequestMapping("register6")
    public BaseRespVo register6(String username, String password, Integer age,
                                String[] hobbies,
                                Integer[] ids,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        return BaseRespVo.ok("register6:" + hobbies + "-->" + ids);
    }*/

    //localhost:8080/user/query?age=20&page=2&limit=10
    @RequestMapping("query")
    public BaseRespVo query(Integer age, PageInfo pageInfo) {
        return BaseRespVo.ok("成功", pageInfo);
    }

    // 就上面这个请求，我能否用一个引用类型的对象来接收呢
    @RequestMapping("query1")
    public BaseRespVo query1(QueryBo queryBo) {
        return BaseRespVo.ok("成功", queryBo);
    }
    // 就上面这个请求，我能否 再 换一个引用类型的对象来接收呢
    @RequestMapping("query2")
    public BaseRespVo query2(QueryBo2 queryBo2) {
        return BaseRespVo.ok("成功", queryBo2);
    }


    // 接收Json数据
    @RequestMapping("login")
    public BaseRespVo login(@RequestBody String parameter) {
        return BaseRespVo.ok(null);
    }

    @RequestMapping("login2")
    public BaseRespVo login2(@RequestBody JsonUser jsonUser) {
        return BaseRespVo.ok(null,jsonUser);
    }

    @RequestMapping("login3")
    public BaseRespVo login3(@RequestBody Map map) {
        return BaseRespVo.ok(null);
    }

}
